package com.example.scaletest.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by LK on 2016/10/19.
 */
public class DataBaseHelper extends SQLiteOpenHelper{
    private static final String DB_NAME = "BindData.db";
    private static volatile DataBaseHelper instance = null;
    public static final String T_INFO = "t_info";
    public static final String ID = "id";
    public static final String BATCH_ID = "batch_id";
    public static final String DEVICE_ID = "device_id";
    public static final String GOODS_ID = "goods_id";
    public static final String CREATE_INFO_TABLE="create table "+ T_INFO +" ( "
            + ID +" integer primary key autoincrement, " +
            BATCH_ID +" text, " +
            DEVICE_ID +" text, "+
            GOODS_ID + " text"+")";
    public DataBaseHelper(Context context) {
        super(context, DB_NAME, null, 1);
    }

    public static DataBaseHelper getInstance(Context context){
        if (instance == null){
            synchronized (DataBaseHelper.class){
                if (instance == null){
                    DatabaseContext dbContext = new DatabaseContext(context);
                    instance = new DataBaseHelper(dbContext);
                }
            }
        }
        return instance;
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_INFO_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public SQLiteDatabase open(){
        return getReadableDatabase();
    }

    public void close(){
        super.close();
    }
}
